﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;

namespace ReaWTM.LayuiHelper.Extensions
{
	public static class UIServiceExtension
	{
		public static string MakeTableCellTextBox(string name = null, string value = null, string emptyText = null, string layVerify = null, string slot = null)
		{
			string style = null, verify = null;
			if (!string.IsNullOrEmpty(layVerify))
			{
				verify = $" lay-verify='{layVerify}'";
				style = $" style='background-color:pink;'";
			}
			return $@"<input class='layui-input' name='{name ?? ""}' id='{(name == null ? "" : Utils.GetIdByName(name))}' value='{value ?? ""}' {verify} {style} {slot}/>";
		}
		public static string MakeTableCellCombo(string name = null, List<ComboSelectListItem> value = null, string selectedValue = null, string emptyText = null, string layVerify = null, string slot = null)
		{
			string style = null, verify = null;
			if (!string.IsNullOrEmpty(layVerify))
			{
				verify = $" lay-verify='{layVerify}'";
				style = $" style='background-color:pink;'";
			}
			StringBuilder rv = new StringBuilder($"<select class='layui-input' lay-ignore name='{name}' id='{(name == null ? "" : Utils.GetIdByName(name))}' {verify} {slot} {style}>");
			if (string.IsNullOrEmpty(emptyText) == false)
			{
				rv.Append($@"<option value=''>{emptyText}</option>");
			}
			if (value != null)
			{
				foreach (var item in value)
				{
					if (item.Value.ToString().ToLower() == selectedValue?.ToLower())
					{
						rv.Append($@"<option value='{item.Value}' selected>{item.Text}</option>");
					}
					else
					{
						rv.Append($@"<option value='{item.Value}'>{item.Text}</option>");
					}
				}
			}
			rv.Append($@"</select>");
			return rv.ToString();
		}

	}
}
